package com.yellowcong;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

import com.yellowcong.filter.EncoderFilter;
import com.yellowcong.servlet.DemoServlet;

@SpringBootApplication
public class ConfigMain {  
	  
	/**
	 * 
	 * @return
	 */
	@Bean  
    public FilterRegistrationBean filterCodeRegistration() {  
        FilterRegistrationBean registration = new FilterRegistrationBean();  
        registration.setFilter(new EncoderFilter());
        //设定匹配的路径
        registration.addUrlPatterns("/*");
        //设定加载的顺序
        registration.setOrder(2);  
        return registration;  
    }
	
	/**
	 * 通过代码来配置servlet
	 * @return
	 */
	@Bean  
    public ServletRegistrationBean servletDemoRegistration() {  
        ServletRegistrationBean registration = new ServletRegistrationBean();
        registration.setServlet(new DemoServlet());
        registration.addInitParameter("key", "yellowcong");
        registration.addUrlMappings("/doubi");
        registration.setOrder(2);
        return registration;
    }
	
	
    public static void main(String[] args) {  
        SpringApplication.run(ConfigMain.class, args);  
    }  
}
